import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:go_router/go_router.dart';

import '../routers/index.dart';

class NavigationHelper {
  static void navigate_to(String route_name, {dynamic arguments}) {
    // 使用go_router导航
    RouteUtil.push(route_name, extra: arguments);
  }

  static void go_back<T>([T? result]) {
    final context = Get.context;
    if (context != null) {
      RouteUtil.pop(result);
    }
  }

  static void replace_to(String route_name, {dynamic arguments}) {
    RouteUtil.replace(route_name, extra: arguments);
  }

  static T? get_arguments<T>(BuildContext context) {
    final extra = GoRouterState.of(context).extra;
    if (extra is T) {
      return extra;
    }

    final get_arguments = Get.arguments;
    if (get_arguments is T) {
      return get_arguments;
    }

    return null;
  }
}
